using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace InputProductForm
{
    class TProduct
    {
        UTLDB.UTLDB _cn = new UTLDB.UTLDB();
        public int InsertShell(InfoShell info){
            int id = _cn.ExecuteInsert("sp_InserttblShell",
               new string[] { "@Weight", "@Price", "@IDMaterial", "@UnitID"},
               new object[] { info.Weight, info.Price, info.IDMaterial, info.UnitID });
            return id;
 
        }
        public int InsertSeed(InfoSeed info) {
            int id = _cn.ExecuteInsert("sp_InserttblSeed",
              new string[] { "@Name", "@Size", "@IDUnit", "@Price", "@DatePrice" },
              new object[] { info.Name, info.Size, info.IDUnit, info.Price, info.DatePrice });
            return id;
        }
        public void UpdateSeed(InfoSeed info)
        {
              int id = _cn.ExecuteNonQuery("sp_UpdatetblSeed",
              new string[] {"@id", "@Name", "@Size", "@IDUnit", "@Price", "@DatePrice" },
              new object[] {info.Id, info.Name, info.Size, info.IDUnit, info.Price, info.DatePrice });
        }

     
        public DataTable SelectSeed(string Name)
        {
            DataTable data = _cn.GetDataByStoredProcedure("sp_SelecttblSeed",
                new string[] { "@Name" },
                new object[] { Name });
            return data;
        }
        public DataTable SelectMetarial() {
            DataTable data = _cn.GetDataBySQL("SELECT * FROM [tblMaterial]");
            return data;
        }
        public DataTable SelectUnit()
        {
            DataTable data = _cn.GetDataBySQL("SELECT * FROM [tblUnit]");
            return data;
        }
        public int InsertProduct(InfoProduct info)
        {
            int id = _cn.ExecuteInsert("sp_InserttblProduct",
                new string[] { "@Name", "@Barcode", "@IDCat", "@IDShell", "@IDSeedLarge","@NumberSeedLarge","@IDSeedSmall","@NumberSeedSmall","@TienCong","@Status" },
                new object[] { info.Name , info.Barcode, info.IDCat,info.IDShell, info.IDSeedLarge, info.NumberSeedLarge, info.IDSeedSmall, info.NumberSeedSmall, info.TienCong, info.Statue });
            return id;
        }
        public string GetMaxID() {
            DataTable data = _cn.GetDataBySQL("SELECT MAX(ID) AS MaxID FROM [tblProduct]");
            return data.Rows[0]["MaxID"].ToString();
        }
        public DataTable LoadProductWithStatus(int status) {

            DataTable data = new DataTable();
            data = _cn.GetDataByStoredProcedure("sp_SelecttblProduct_status",
               new string[] { "@Status" },
               new object[] {status}
                );
            return data;
        }
    }
}
